<?php
class Embed extends BlockInstance {
	public $CI;
	
	function Embed()
	{
		$this->CI =& get_instance();
	}
	
	function __call($m, $a)
	{
		global $BBX;
		
		if (preg_match('/[a-z]+_([a-z]+)/', $m, $matches))
		{
			if ($matches[1] == 'content')
			{
				$content = $a[1];
				$code    = $this->get_setting($a[0]['data'], 'code', $content->id);
				$data 	 = array(
					'block_instance' => $a[0],
					'code'			 => $code,
					'bricabox'		 => $BBX['bricabox'],	// pass anyway so handle_proxy() can recreate the view via ajax
					'content'		 => $content			// pass anyway so handle_proxy() can recreate the view via ajax
				);
				$data['inst']  = $a[0]['data'];
				$data['value'] = $code;
				$this->CI->load->view('blocks/embed/content', $data);
			}
			elseif ($matches[1] == 'homepage')
			{
				$query = $this->CI->db->query('select content_id,value from meta_settings
					where content_id in (select contents.id from contents where contents.bricabox_id = ?)
						and meta_settings.name = ?
					limit 5',
					array(
						$BBX['bricabox']->id,
						'code'
					));
				$data = array(
					'bricabox'		 => $BBX['bricabox'],	// pass anyway so handle_proxy() can recreate the view via ajax
					'block_instance' => $a[0],
					'ent'			 => $query
				);
				$this->CI->load->view('blocks/embed/homepage', $data);
			}
		}
	}
}
?>